package com.jiuyou.clientController;

import com.ruoyi.comment.domain.Comment;
import com.ruoyi.comment.service.ICommentService;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.core.controller.HandleVideoSrc;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.fitment.domain.StoreFitment;
import com.ruoyi.fitment.service.IStoreFitmentService;
import com.ruoyi.shopping.domain.Bbs;
import com.ruoyi.shopping.domain.MallComment;
import com.ruoyi.shopping.domain.MallProduct;
import com.ruoyi.shopping.domain.MallProductBack;
import com.ruoyi.shopping.service.IBbsService;
import com.ruoyi.shopping.service.IMallCommentService;
import com.ruoyi.shopping.service.IMallProductBackService;
import com.ruoyi.shopping.service.IMallProductService;
import com.ruoyi.store.domain.Store;
import com.ruoyi.store.service.IStoreService;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.teaching.domain.PlatformTeaching;
import com.ruoyi.teaching.service.IPlatformTeachingService;
import com.ruoyi.technicianOpus.domain.StoreTechnicianOpus;
import com.ruoyi.technicianOpus.service.IStoreTechnicianOpusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author chengliang
 * @date 2022/8/25
 **/
@RestController
    @RequestMapping("/client/qwkjhgertyplkjhgfdsuioa")
public class handleOldData {
    @Autowired
    private IPlatformTeachingService teachingService;
    @Autowired
    private IBbsService bbsService;
    @Autowired
    private IMallProductService productService;
    @Autowired
    private IMallProductBackService backService;
    @Autowired
    private ICommentService commentService;
    @Autowired
    private IMallCommentService mCommentService;
    @Autowired
    private ISysConfigService configService;
    @Autowired
    private IStoreService storeService;

    @Autowired
    private IStoreFitmentService fitmentService;
    @Autowired
    private IStoreTechnicianOpusService opusService;
    @RequestMapping("/handleVideoCover")
    private void handleVideoCover(){
        Map<String, String> val = configService.getVal();
        String key = val.get("key");
        String id = val.get("id");
        String region = val.get("region");
        String bn = val.get("bn");

        StoreFitment fi = new StoreFitment();
        fi.setFitmentType(DicConstants.FITMENT_TYPE_SINGLE.getCode());
        List<Store> stores = storeService.selectStoreList(new Store());
        stores.forEach(e->{
            String storeBacImage = e.getStoreBacImage();
            fi.setStoreId(e.getId());
            fi.setPicUrl(storeBacImage);
            fitmentService.insertStoreFitment(fi);
        });

        List<MallComment> list = mCommentService.selectMallCommentList(new MallComment());
        list.forEach(e->{
            if(StringUtils.isNotEmpty(e.getCommentVideo())){
                e.setVideoCover(HandleVideoSrc.handle(key,id,region,bn,e.getCommentVideo()));
                mCommentService.updateMallComment(e);
            }
        });
        List<StoreTechnicianOpus> storeTechnicianOpuses = opusService.selectStoreTechnicianOpusList(new StoreTechnicianOpus());
        storeTechnicianOpuses.forEach(e->{
            if(StringUtils.isNotEmpty(e.getOpusVideoUrl())){
                e.setVideoCover(HandleVideoSrc.handle(key,id,region,bn,e.getOpusVideoUrl()));
                opusService.updateStoreTechnicianOpus(e);
            }
        });
        List<PlatformTeaching> platformTeachings = teachingService.selectPlatformTeachingList(new PlatformTeaching());
        platformTeachings.forEach(e->{
            if(StringUtils.isNotEmpty(e.getTeachUrl())){
                e.setVideoCover(HandleVideoSrc.handle(key,id,region,bn,e.getTeachUrl()));
                teachingService.updatePlatformTeaching(e);
            }
        });
        List<Bbs> bbs = bbsService.selectBbsList(new Bbs());
        bbs.forEach(e->{
            if(StringUtils.isNotEmpty(e.getVideoList())){
                e.setVideoCover(HandleVideoSrc.handle(key,id,region,bn,e.getVideoList()));
                bbsService.updateBbs(e);
            }
        });
        List<MallProduct> productList = productService.selectMallProductList(new MallProduct());
        productList.forEach((e->{
            if(StringUtils.isNotEmpty(e.getProductMainVideo())){
                e.setVideoCover(HandleVideoSrc.handle(key,id,region,bn,e.getProductMainVideo()));
                productService.updateMallProduct(e);
            }
        }));

        List<MallProductBack> mallProductBacks = backService.selectMallProductBackList(new MallProductBack());
        mallProductBacks.forEach(e->{
            if(StringUtils.isNotEmpty(e.getProductMainVideo())){
                e.setVideoCover(HandleVideoSrc.handle(key,id,region,bn,e.getProductMainVideo()));
                backService.updateMallProductBack(e);
            }
        });
        List<Comment> comments = commentService.selectCommentList(new Comment());
        comments.forEach(e->{
            if(StringUtils.isNotEmpty(e.getCommentVideo())){
                e.setVideoCover(HandleVideoSrc.handle(key,id,region,bn,e.getCommentVideo()));
                commentService.updateComment(e);
            }
        });
    }

}
